<!DOCTYPE html>
<html lang="en" xml:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>缺勤信息管理</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/css/custom.form.css">
</head>
<body>
<!--数据与分页-->
<div class="user_table_div">
    <!--多条件查询-->
    <div id="searchParam">
        <div class="layui-form-item">
            <div class="layui-input-inline">
                <input type="text" id="name" class="layui-input" autocomplete="off" placeholder="name">
            </div>
            <div class="layui-input-inline ">
                <button class="layui-btn" id="search">查询</button>
            </div>
        </div>
    </div>
    <!--显示数据的表格-->
    <table class="layui-hide" id="user_table" lay-filter="user_table"></table>
    <!--分页相关 View-->
    <div id="laypage" class="layui-laypage-btn"></div>
</div>


</body>
<script src="/layui/layui.js"></script>
<script src="/js/core.util.js"></script>
<script src="/js/xm-select.js"></script>
<!--新增缺勤按钮、批量删除 按钮-->
<!--给缺勤赋予角色按钮-->
<!--shiro:hasPermission="sys:user:role:update"  shiro:hasPermission="sys:user:update" shiro:hasPermission="sys:user:delete" -->
<script>

    layui.use(['jquery', 'form', 'table', 'laypage', 'layer', 'laydate', 'tree', 'transfer'], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var table = layui.table;
        var laypage = layui.laypage
        var layer = layui.layer;
        var laydate = layui.laydate;

        /*分页参数*/
        var searchParam = {
            pageNum: 1,
            pageSize: 10,
            /*以下为多条件查询参数*/
            name: null
        }

        /*动态获取数据*/
        var reloadTreeTable = function () {
            CoreUtil.sendAjax("/dormitory/absentfromwork/page", searchParam, function (res) {

                //初始化分页器
                laypageTable(res.page.totalCount, searchParam.pageNum);
                //初始化渲染数据
                loadTable(res.page.list);
                if (res.page.list != null) {
                    loadTable(res.page.list);
                }
            }, "GET", false, function (res) {
                //缺勤列表接口无权限回调
                layer.msg("抱歉！您暂无获取缺勤列表的权限");
                var noAuthorityData = [];
                loadTable(noAuthorityData);
            });
        }
        //渲染分页插件
        var laypageTable = function (count, currentPage) {
            laypage.render({
                elem: 'laypage'
                , count: count
                , limit: searchParam.pageSize
                , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
                , curr: location.hash.replace('#!currentPage=', '')     //获取起始页
                , hash: 'currentPage'                                   //自定义hash值
                , jump: function (obj, first) {
                    if (!first) {
                        searchParam.pageNum = obj.curr;
                        searchParam.pageSize = obj.limit;
                        CoreUtil.sendAjax("/dormitory/absentfromwork/page", searchParam, function (res) {
                            if (res.page.list != null) {
                                loadTable(res.page.list);
                                laypageTable(res.page.totalCount, searchParam.pageNum);
                            }
                        }, "GET", false, function (res) {
                            //缺勤列表接口无权限回调
                            layer.msg("抱歉！您暂无获取缺勤列表的权限");
                            var noAuthorityData = [];
                            loadTable(noAuthorityData);
                        });
                    }
                }
            });
        };
        //渲染table
        var loadTable = function (data) {
            //展示已知数据
            table.render({
                elem: '#user_table'
                // 这个 data 为数组数据，直接 放到 data 上即可。
                , data: data
                , even: true
                , limit: data.length
                , limits: [10, 20, 30, 40, 50]
                , toolbar: '#toolbar'
                , cols: [
                    [
                        {type: 'checkbox', fixed: 'left'},
                        {field: 'id', title: 'ID', width: 300, sort: true},
                        {field: 'studentName', title: '学生姓名', width: 230},
                        {field: 'sno', title: '学号', width: 230},
                        {field: 'reason', title: '原因', width: 230},
                        {
                            field: 'time', title: '时间', minWidth: 120, templet: function
                                (item) {
                                return CoreUtil.formattime(item.time);
                            }
                        }
                    ]
                ]
            });
        };
        reloadTreeTable();

        //编辑或新增的界面取消事件
        $("#btn_cancel").click(function () {
            //显示表格
            $(".user_table_div").show();
            //隐藏编辑窗口
            $(".operation_user").hide();
            //可以防止在表单事件操作后自动刷新
            return false;
        });


        //执行查询
        $("#search").click(function () {
            searchParam.name = $("#name").val();
            searchParam.pageNum = 1;
            CoreUtil.sendAjax("/dormitory/absentfromwork/page", searchParam, function (res) {
                if (res.page.list != null) {
                    loadTable(res.page.list);
                    laypageTable(res.page.totalCount, searchParam.pageNum);
                }
            }, "GET", false, function (res) {
                //缺勤列表接口无权限回调
                layer.msg("抱歉！您暂无获取缺勤列表的权限");
                var noAuthorityData;
                noAuthorityData = [];
                loadTable(noAuthorityData);
            });
        });

        // 渲染时间
        laydate.render({
            elem: '.createTime'
            , position: 'static'
            , change: function (value, date) { //监听日期被切换
                lay('#testView').html(value);
            }
        });
    });
</script>
</html>

